import { defineStore } from 'pinia'
import account from '@/assets/svg/account.svg'
import level from '@/assets/svg/level.svg'
import task from '@/assets/svg/task.png'
import user from '@/assets/svg/user.png'
export const useSideStore = defineStore({
  // id: 必须的，在所有 Store 中唯一
  id: "side",
  // a function that returns a fresh state
  state: () => {
    return {
      token: '',
      isCollapse: false, // 缺少侧边栏折叠状态
      defaultActive: '1', // 缺少默认激活菜单项
      menuList: [
        {
          title: '账号管理',
          path: '/admin/manager',
          icon: account,
          id: 1
        },
        {
          title: '评委管理',
          path: '/admin/user',
          icon: user,
          id: 2
        },
        {
          title: '组名管理',
          path: '/admin/level',
          icon: level,
          id: 3
        },
        {
          title: '任务管理',
          path: '/admin/task',
          icon: task,
          id: 5
        },
      ]
    }
  },
  // optional actions
  actions: {
    // 缺少操作方法
    setCollapse(value) {
      this.isCollapse = value
    },
    setDefaultActive(value) {
      this.defaultActive = value  
    },
    setMenuItem (to) {
      const data = this.menuList.find(item => item.path === to.path)
      if(data){
        this.defaultActive = data?.id
      }
    }
  },
})